@using System.Globalization
@model FluentBlog.ViewModels.FeedViewModel


<!-- 动态 -->
<div class="card shadow p-3 mb-4">
    <div class="card-header bg-white px-1 py-2">
        <h5 class="font-weight-normal"><i class="mi mi-Feedback"></i> 动态</h5>
    </div>
    <div class="card-body p-1">
        <blockquote class="blockquote mt-2">
            <!-- 博主 -->
            <h6 class="font-weight-bold">@@@Model.Authors[0].DisplayName：</h6>
            <!-- 动态内容 -->
            <p class="mb-1 small">@Model.Feeds[0].Text</p>
            <!-- 时间 -->
            <span class="text-muted small">
                <i class="mi mi-ClockLegacy small" data-toggle="tooltip" data-placement="top" title="发布时间"></i> @Model.Feeds[0].Created.ToString(CultureInfo.CurrentCulture)
            </span>
            <br />
            <!-- 点赞 -->
            @if (Model.LikedList[0])
            {
                <a class="text-muted text-primary small" id="likes">
                    <i class="mi mi-Like small" data-toggle="tooltip" data-placement="top" title="已赞" id="likesIcon"></i>
                    <span id="likesCount">@Model.Feeds[0].Likes</span>
                </a>
            }
            else
            {
                <a class="text-muted small" onclick="addLikesCount(@Model.Feeds[0].Fid)" href="javascript:void(0);" id="likes">
                    <i class="mi mi-Like small" data-toggle="tooltip" data-placement="top" title="赞" id="likesIcon"></i>
                    <span id="likesCount">@Model.Feeds[0].Likes</span>
                </a>
            }
        </blockquote>
    </div>
    <!-- 数据 -->
    <div class="card-footer bg-transparent d-flex justify-content-around px-0">
        <div class="ml-auto">
            <!-- 更多 -->
            <a class="card-link small d-block text-right" asp-controller="Home" asp-action="Feed">
                查看更多
                <i class="mi mi-ChevronRight small"></i>
            </a>
        </div>
    </div>
</div>

<!-- Ajax实现点赞 -->
<script type="text/javascript">
    function addLikesCount(fid) {
        $.ajax({
            url: '@Url.Action("AddFeedLikesCount", "Home")',
            type: 'GET',
            dataType: 'json',
            cache: false,
            data: { fid: fid },
            success: function(feed) {
                $('#likes').addClass("text-primary");
                $('#likes').removeAttr("href");
                $('#likes').removeAttr("onclick");
                $('#likesIcon').attr("data-original-title", "已赞");
                $('#likesCount').text(feed["likes"]);
            }
        });
    }
</script>